package com.ruibang.glass.quality.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.quality.domain.req.DiscardDefectReq;
import com.ruibang.glass.quality.domain.req.EverydayDiscardDefectReq;
import com.ruibang.glass.quality.entity.EverydayBandDefect;
import com.ruibang.glass.quality.mapper.EverydayBandDefectMapper;
import com.ruibang.glass.quality.service.EverydayBandDefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-09-18  16:58
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@Slf4j
public class EverydayBandDefectServiceImpl extends ServiceImpl<EverydayBandDefectMapper, EverydayBandDefect> implements EverydayBandDefectService {


    @Override
    public void deleteByDate(DiscardDefectReq defectReq) {
        baseMapper.deleteByDate(defectReq);
    }
    @Override
    public List<EverydayBandDefect> getByDate(ArrayList<String> date) {
        QueryWrapper<EverydayBandDefect> hlQw = new QueryWrapper<>();
        hlQw.lambda().in(EverydayBandDefect::getDiscardDate, date);
        return this.list(hlQw);
    }


    /**
     * @Description: 查询每日待投判废缺陷数据（分页）
     * @version v1.0
     * @author songJinKang
     * @date 2023-09-18 21:40
     */
    @Override
    public ResultBody queryPageEveryHourColdDirect(EverydayDiscardDefectReq everydayDiscardDefectReq) {
        QueryWrapper<EverydayBandDefect> qwBd = new QueryWrapper<>();
        qwBd.lambda().ge(everydayDiscardDefectReq.getStartTime() != null, EverydayBandDefect::getDiscardDate, everydayDiscardDefectReq.getStartTime());
        qwBd.lambda().le(everydayDiscardDefectReq.getEndTime() != null, EverydayBandDefect::getDiscardDate, everydayDiscardDefectReq.getEndTime());
        qwBd.lambda().eq(StringUtils.isNotBlank(everydayDiscardDefectReq.getCheckMachineCode()), EverydayBandDefect::getCheckMachineCode, everydayDiscardDefectReq.getCheckMachineCode());
        qwBd.lambda().orderByDesc(EverydayBandDefect::getDiscardDate);
        Page<EverydayBandDefect> pageData = baseMapper.selectPage(new Page<>(everydayDiscardDefectReq.getPageNo(), everydayDiscardDefectReq.getPageSize()), qwBd);
        return ResultBody.success(pageData);

    }

    /**
     * @Description:
     * @version v1.0
     * @author songJinKang
     * @date 2023-09-18 22:48
     */
    @Override
    public ResultBody queryEverydayBandDefect(EverydayDiscardDefectReq everydayDiscardDefectReq) {
        QueryWrapper<EverydayBandDefect> qwBd = new QueryWrapper<>();
        qwBd.lambda().ge(everydayDiscardDefectReq.getStartTime() != null, EverydayBandDefect::getDiscardDate, everydayDiscardDefectReq.getStartTime());
        qwBd.lambda().le(everydayDiscardDefectReq.getEndTime() != null, EverydayBandDefect::getDiscardDate, everydayDiscardDefectReq.getEndTime());
        qwBd.lambda().eq(StringUtils.isNotBlank(everydayDiscardDefectReq.getCheckMachineCode()), EverydayBandDefect::getCheckMachineCode, everydayDiscardDefectReq.getCheckMachineCode());
        qwBd.lambda().orderByDesc(EverydayBandDefect::getDiscardDate);
        return ResultBody.success(this.list(qwBd));
    }

}
